#include "hw/board.h"
#include "messages.hpp"
#include <avr/io.h>
#include <supervisor.h>

using Queue = rl::Queue<Storage, 15>;
using Planner = rl::Planner<5>;

Supervisor sup;

int main(int, char **) {
  hw::Board::init_start();
  hw::Board::enable_timer();
  hw::Board::enable_uart();
  sei();

  Queue queue;
  Planner planner;
  rl::Context context{&queue, &planner, &hw::Board::get_now};
  sup.bind(context);

  auto dht = sup.get_child<0>();
  auto uart = sup.get_child<1>();
  dht->uart_id = uart->get_id();

  sup.start(true);

  /* main cycle */
  sup.process();

  return 0;
}

void on_rx(char c) {}
void on_tx() { sup.get_child<1>()->send_next(true); }


namespace std {
void __throw_bad_optional_access() {
    while(1) {}
}
}
